// 引入路由
import Router from 'next/router'
import React from 'react'
import '../styles/error.scss'
export default class ErrorPage extends React.Component{

    constructor(props) {
        super(props);
        this.state = {
            toHomeTime: 3,
            timeId: ''
        }
    }
    componentDidMount(){
        this.state.timeId = setInterval(() => {
            if(this.state.toHomeTime > 0){
                this.setState({
                    toHomeTime: this.state.toHomeTime-1
                })
            }else{
                Router.push('/')
            }
        },1000)
    }
    render(){
        return (
            <div className='error_page'>
                <div className='error'>
                    <h2 className='error_fl'>404</h2>
                    <div className='error_fr'>
                        <span>页面找不到了！</span>
                        <span> <i>{this.state.toHomeTime}</i> 秒后跳转至首页。</span>
                    </div>
                </div>
            </div>
        )
    }
    componentWillUnmount(){
        clearInterval(this.state.timeId)
    }
}